<template>
	<view class="select-container">
		<view class="text" :class="selOptions.length ? 'open':'close'" @click="isShowModal = true">
			<text>{{selOptionsText}}</text>
			<img class="icon" v-if="isShowModal" src="/schoolCube/static/svg/top.svg" alt="">
			<img class="icon" v-else-if="selOptions.length" src="/schoolCube/static/svg/bottom-active.svg" alt="">
			<img class="icon" v-else src="/schoolCube/static/svg/bottom.svg" alt="">
		</view>
		<CustomModal v-if="isShowModal" :isShowPopup="isShowModal" :title="selectTitle" :options="options"
			:selOptions="selOptions" :multiple="multiple" :multipleArr="multipleArr" @close="isShowModal=false"
			@confirm="confirm" />
	</view>
</template>

<script>
	export default {
		name: "custom-select",
		props: {
			title: {
				type: String,
				default: '',
			},
			selectTitle: {
				type: String,
				default: '',
			},
			options: {
				type: Array,
				default: () => ([])
			},
			selOptions: {
				type: Array,
				default: () => ([])
			},
			multiple: {
				type: Boolean,
				default: false,
			},
			multipleArr: {
				type: Boolean,
				default: false,
			},
			isSelect: {
				type: Boolean,
				default: false,
			},
		},
		data() {
			return {
				isShowModal: false,
			}
		},
		computed: {
			selOptionsText(){
				if(!this.selOptions.length){
					return this.title;
				} else {
					return this.selOptions.map(item => item.label).join(',')
				}
			}
		},
		methods: {
			confirm(values) {
				this.isShowModal = false;
				this.$emit('confirm', values);
			}
		}
	}
</script>

<style lang="scss" scoped>
	.select-container {
		display: inline-flex;
	}

	.text {
		display: inline-flex;
		box-sizing: border-box;
		border: 2rpx solid #999999;
		color: #999999;
		height: 56rpx;
		border-radius: 10rpx;
		font-size: 26rpx;
		padding: 12rpx;
		align-items: center;
		text{
			max-width: 150rpx;
			text-overflow: ellipsis;
			overflow: hidden;
			white-space: nowrap;
		}

		.icon {
			width: 20rpx;
			height: 20rpx;
		}
	}

	.text.open {
		border: 2rpx solid #2979FF;
		color: #2979FF;
	}
</style>